﻿@{
    var condtions = Model.Data["conditions"];
    var columns = Model.Data["columns"];
    var controller = Model.Data["controller"];

    var usingPlugins = new List<string>();
    var plugins = new List<string>() {"numberbox","datebox","validatebox"};
    foreach (var item in columns)
    {
        var editor = item.Value<string>("editor");
        foreach(var plugin in plugins)
        {
            var quotePlugin = string.Format("'{0}'", plugin);
            if (editor.IndexOf(plugin) > -1 && !usingPlugins.Contains(quotePlugin))
            {
                usingPlugins.Add(quotePlugin);
            }
        }
    }
}
@@{
    ViewBag.Title = "@controller";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@@section scripts{
<script src="~/Content/js/viewModel/com.viewModel.searchEdit.js"></script>
<script type="text/javascript">
    @if (usingPlugins.Count > 0)
    {
    @:using([@Raw(string.Join(",", usingPlugins.ToArray()))]);
    }
    var data = @@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model));
    ko.bindingViewModel(new com.viewModel.searchEdit(data));
</script>
}
<div class="z-toolbar">
    <a href="#" plain="true" class="easyui-linkbutton"  icon="icon-arrow_refresh"   title="刷新" data-bind="click:refreshClick">刷新</a>
    <a href="#" plain="true" class="easyui-linkbutton"  icon="icon-add"             title="新增" data-bind="click:addClick"    >新增</a>
    <a href="#" plain="true" class="easyui-linkbutton"  icon="icon-edit"            title="编辑" data-bind="click:editClick"   >编辑</a>
    <a href="#" plain="true" class="easyui-linkbutton"  icon="icon-cross"           title="删除" data-bind="click:deleteClick" >删除</a>
    <a href="#" plain="true" class="easyui-linkbutton"  icon="icon-save"            title="保存" data-bind="click:saveClick"   >保存</a>
    <a href="#" plain="true" class="easyui-splitbutton" data-options="menu:'#dropdown',iconCls:'icon-download'"                >导出</a>
</div>

<div id="dropdown" style="width:100px; display:none;">  
    <div data-options="iconCls:'icon-ext-xls'"      suffix="xls"    data-bind="click:downloadClick">Excel2003   </div>  
    <div data-options="iconCls:'icon-page_excel'"   suffix="xlsx"   data-bind="click:downloadClick">Excel2007   </div>  
    <div data-options="iconCls:'icon-ext-doc'"      suffix="doc"    data-bind="click:downloadClick">Word2003    </div>  
</div> 

<div class="container_12" style="position:relative;">
@for (var i = 0; i < condtions.Count; i++)
{
    if (i % 3 == 0 && i>0)
    {
    @:
    <div class="clear"></div>
    @:
    }

    var item = condtions[i];
    var textPlugin = new List<string>() { "text", "autocomplete", "daterange" };
    var type = item.type.ToString();
    var cls = type == "text" ? "" : ("easyui-" + type);
    var val = textPlugin.Contains(type) ? "value" : (type + "Value");
    <div class="grid_1 lbl">@item.title</div>
    <div class="grid_2 val"><input type="text" data-bind="@val:form.@item.field" class="z-txt @cls" @Raw(item.options.ToString() == "" ? "" : "data-options=\"" + item.options + "\"")/></div>
}

    @if (condtions.Count < 4)
    {
    <div class="clear"></div>
        
    <div class="grid_1 lbl">&nbsp;</div>
    <div class="grid_2 val">&nbsp;</div>
        
    }
    <div class="clear"></div>

    <div class="prefix_9" style="position:absolute;top:5px;height:0;">  
        <a id="a_search" href="#" class="buttonHuge button-blue" data-bind="click:searchClick" style="margin:0 15px;">查询</a> 
        <a id="a_reset"  href="#" class="buttonHuge button-blue" data-bind="click:clearClick">清空</a>
    </div>
</div>

<table data-bind="datagrid:grid" style="display:none">
    <thead>  
        <tr>  
        @foreach (var c in columns)
        {
            var hasFmt = c.formatter.ToString() != "";
            var hasEdt = c.editor.ToString() != "";
            var hidden = c.Value<bool>("hidden");
            <th field="@c.field"@Raw("\t")@Raw(hidden ? "hidden=\"true\"" : "")@Raw("\t")sortable="@c.sortable.ToString().ToLower()"@Raw("\t")align="@c.align"@Raw("\t")width="@c.width" @Raw(hasEdt ? "editor=\"" + @c.editor + "\"" : "") @Raw(hasFmt ? "formatter=\"" + c.formatter + "\"" : "")>@c.title</th>
        }
        </tr>                            
    </thead>      
</table> 